using System;
using System.Collections.Generic;
using System.Text;

namespace GPSCore
{
    /// <summary>
    /// Speed Object
    /// The value rappresent ALWAYS the speed value in meters / seconds unit of mesure
    /// </summary>
    public class Speed : IComparable<Speed>, IComparer<Speed>, IEquatable<Speed>
    {
        #region membres

        private double _value;

        #endregion

        #region constructors

        /// <summary>
        /// Build a Speed object
        /// </summary>
        public Speed()
        {
            _value = 0;
        }

        /// <summary>
        /// Build a Speed object (value must be >= 0)
        /// </summary>
        /// <param name="value"></param>
        public Speed(double value)
        {
            if (value >= 0)
                _value = value;
            else
                _value = 0;
        }

        #endregion
        
        #region properties

        /// <summary>
        /// Speed Value in meters / seconds
        /// </summary>
        public double Value
        {
            get { return _value; }
            set { _value = value; }
        }

        #endregion


        #region IComparable<Speed> Members

        int IComparable<Speed>.CompareTo(Speed other)
        {
            if (this._value > other._value)
            {
                return 1;
            }
            else
            {
                if (this._value < other._value)
                {
                    return -1;
                }
                else
                {
                    return 0;
                }
            }
        }

        #endregion

        #region IComparer<Speed> Members

        int IComparer<Speed>.Compare(Speed x, Speed y)
        {
            if (x._value > y._value)
            {
                return 1;
            }
            else
            {
                if (x._value < y._value)
                {
                    return -1;
                }
                else
                {
                    return 0;
                }
            }
        }

        #endregion

        #region IEquatable<Speed> Members

        bool IEquatable<Speed>.Equals(Speed other)
        {
            if (this._value.Equals(other._value))
                return true;
            else
                return false;
        }

        #endregion
    }
}
